/*
 * @Author: linZeJian
 * @Date: 2022-09-02 11:11:26
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-09-06 10:41:17
 * @Description: 
 */

import request from "@/utils/request.js";
import idaas from "@/apis/idaas";
import filebase from "@/apis/filebase";
import bmo from "@/apis/bmo";

export default {
  idaas,
  filebase,
  bmo,

  //获取当前登录
  async getLoginUserInfo() {
    let res = await request.get(`/api/me`, {
      params: {
        useBindPool: true
      },
      baseURL: process.env.VUE_APP_USER_API,
    });
    return res;
  },

  //新增或更新
  async fullItems(obj) {
    let res = await request.post(`user/project/modify/full/items`, obj, {
      baseURL: process.env.VUE_APP_LUOSHU_API,
    });
    return res;
  },

  //表单详情
  async formModel(id) {
    let res = await request.get(`form/models/${id}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //表单模型列表
  async formModelList(params) {
    let res = await request.get(`form/models`, {
      params,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //新增表单模型
  async formModelSave(obj) {
    let res = await request.post(`form/models`, obj, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //查询表单详情
  async formModelDetails(id) {
    let res = await request.get(`form/model/${id}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //提交表单数据
  async fromDataSend(obj) {
    let res = await request.post(`from/data/send`, obj, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //获取提交的表单数据详情
  async getFormData(dataId) {
    let res = await request.get(`form/data/${dataId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //添加参与人员
  async addFormModelsAuthorityList(modelId, obj) {
    let res = await request.put(`form/models/authority/${modelId}`, obj, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //表单权限
  async getFormModelsAuthorityList(modelId) {
    let res = await request.get(`form/models/authority/list/${modelId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //表单模型发布
  async formModelDeploy(modelId) {
    let res = await request.put(
      `form/models/${modelId}/deploy`, {}, {
        baseURL: process.env.VUE_APP_LS,
      }
    );
    return res;
  },
  //表单模型版本列表
  async modelVersionList(modelId) {
    let res = await request.get(`form/models/${modelId}/versions`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //回滚表单模型版本
  async formModelResetVersion(obj) {
    let res = await request.put(`form/models/reset/version`, obj, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //表单发布
  async projectPublish(obj) {
    let res = await request.post(`/user/project/publish`, obj, {
      baseURL: process.env.VUE_APP_LUOSHU_API,
    });
    return res;
  },

  //数据模型列表
  async tableModelList(params) {
    let res = await request.get(`table/models`, {
      params,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //新增数据模型
  async tableModelSave(obj) {
    let res = await request.post(`table/models`, obj, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //查看数据模型详情
  async tableModelDetails(tableId) {
    let res = await request.get(`table/models/${tableId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //删除数据模型
  async tableModelDelete(tableId) {
    let res = await request.delete(`table/models/${tableId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  // ?projectKey=b9d6bb5f7665458a824be2d4c4d61136 & projectName=开心农场
  //  put
  //获取表单的所有节点缩略数据
  async projectItemList(id) {
    let res = await request.get(`/user/project/item/list/${id}`, {
      baseURL: process.env.VUE_APP_LUOSHU_API,
    });
    return res;
  },
  async fileBase(obj) {
    let param = new FormData(); // 创建form对象
    for (let key in obj) {
      param.append(key, obj[key]); // 通过append向form对象添加数据
    }

    let res = await request.post(
      `/api/v1/app/formfile/${Math.random() * 1000000}`,
      param, {
        baseURL: process.env.VUE_APP_FILEBASE,
      }
    );
    return res;
  },

  // 获取流程列表
  async getProcessListByTypeId(id) {
    let res = await request.get(`v1/bpm/client/model/process/form/${id}`, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },

  // 用户中心
  async userTaskList(obj) {
    let res = await request.get(`v1/bpm/process/user/task/list`, {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //我发起的列表
  async getSubList(query) {
    let res = await request.get(`v1/bpm/process/list`, {
      params: query,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //已办列表
  async userTaskComplateList(obj) {
    let res = await request.get(`v1/bpm/process/user/task/complate/list`, {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //抄送列表
  async makeCopyList(obj) {
    let res = await request.get(`v1/bpm/client/msg/make/copy/list`, {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //可发起模型列表
  async processAuthority(obj) {
    let res = await request.get("v1/bpm/client/user/process/authority", {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //审核通过与否
  async processComlpate(obj) {
    let res = await request.post(`v1/bpm/process/comlpate`, obj, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //撤回
  async processRevoke(userProcessId) {
    let res = await request.delete(`v1/bpm/process/revoke/${userProcessId}`, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //审批历史
  async examineHistory(processId) {
    let res = await request.get(`v1/bpm/process/info/${processId}`, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //获取可驳回节点,排序规则-最近的节点在前面
  async flowNodes(id) {
    let res = await request.get(`v1/bpm/process/rejected/flow/nodes/${id}`, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //驳回到指定节点
  async unFlowNodes(obj) {
    let res = await request.post(`v1/bpm/process/rejected/flow/nodes`, obj, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //获取已填写的内置表单数据
  async resultItemsBy(obj) {
    let res = await request.get(`user/project/result/items/by`, {
      params: obj,
      baseURL: process.env.VUE_APP_LUOSHU_USER_API,
    });
    return res;
  },

  //转办
  async turnTo(obj) {
    let res = await request.post(`v1/bpm/process/task/turn/to`, obj, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  async processList(obj) {
    let res = await request.get(`v1/bpm/process/list`, {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //我的转办
  async myTurnTo(obj) {
    let res = await request.get(`v1/bpm/process/my/turn/to`, {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //转办给我的
  async turnToMe(obj) {
    let res = await request.get(`v1/bpm/process/turn/to/me`, {
      params: obj,
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //查询审核人
  async modelAssignee(obj) {
    let res = await request.post(`v1/bpm/client/model/assignee`, obj, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },
  //提交审核
  async putProcess(key, obj) {
    let res = await request.put(`v1/bpm/process/${key}`, obj, {
      baseURL: process.env.VUE_APP_BASE_USER_API,
    });
    return res;
  },

  //提交表单
  async resultCreate(obj) {
    let res = await request.post(`user/project/result/create`, obj, {
      baseURL: process.env.VUE_APP_LUOSHU_USER_API,
    });
    return res;
  },
  //修改提交表单
  async resultUpdate(obj) {
    let res = await request.put(`user/project/result/update`, obj, {
      baseURL: process.env.VUE_APP_LUOSHU_USER_API,
    });
    return res;
  },
  //获取统计列表
  async getProcessModel(formKey, obj) {
    let res = await request.get(`process/form/data/process/model/${formKey}`, {
      params: obj,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //获取列表的可以搜索字段
  async getModelItems(formKey, obj) {
    let res = await request.get(`process/form/project/model/items/${formKey}`, {
      params: obj,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  // 表单统计 我发起的
  async getEFormMy(params) {
    let res = await request.get(`form/data`, {
      params,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  // 抄送给我
  async getEFormCopy(params) {
    let res = await request.get(`message/form/make/copy/list`, {
      params,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  // 消息列表
  async getEFormMsg(params) {
    let res = await request.get(`message/form/msg/list`, {
      params,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //数据视图
  async getDataViewList(params) {
    let res = await request.get(`dynamic/data/view/list`, {
      params,
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  // 创建数据视图
  async createDataView(obj) {
    let res = await request.post(`dynamic/data/view/create`, obj, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //发布数据视图
  async dataViewDeploy(viewId) {
    let res = await request.post(
      `dynamic/data/view/deploy/${viewId}`, {}, {
        baseURL: process.env.VUE_APP_LS,
      }
    );
    return res;
  },

  //数据视图详情
  async getModelDataView(viewId) {
    let res = await request.get(`dynamic/data/view/model/data/${viewId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },

  //根据数据源配置获取数据
  async requestData(val) {
    if (val && val.type && val.url) {
      let obj = {
        get() {
          return request.get(val.url, {
            params: val.json,
            baseURL: "",
          });
        },
        post() {
          return request.post(val.url, val.json, {
            baseURL: "",
          });
        },
        put() {
          return request.put(val.url, val.json, {
            baseURL: "",
          });
        },
        delete() {
          return request.delete(val.url, {
            params: val.json,
            baseURL: "",
          });
        },
      };
      let res = await obj[val.type]();
      return res;
    } else {
      return Promise.reject("数据源未配置或配置错误");
    }
  },
  //删除视图
  async deleteDataView(viewId) {
    let res = await request.delete(`dynamic/data/view/${viewId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //表单数据数据列表 app/form/data/list
  async getAppFormDataList() {
    let res = await request.get(`app/form/data/list`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
  //表单数据数据详情 app/form/data/dataId
  async getAppFormData(dataId) {
    let res = await request.get(`app/form/data/${dataId}`, {
      baseURL: process.env.VUE_APP_LS,
    });
    return res;
  },
};